package dreamCookGame;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.image.BufferedImage;

public class Inventory extends Scene {
	Item[] _items;
	Item _backItem;
	int[] _shiftX;
	int[] _shiftY;
	
	
	public Inventory(){
		super("inventory", "inventoryPlaceholder", null, 0, 0, null, null, null);
		_items = new Item[0];
		String[] backBtnImgs = {"backBtn"};
		_backItem = new Item("exitGame", backBtnImgs, -30, 455, null, null, null, false, null);
		addBackBtn();
		this._itemsBack = _items;
	}
	
	public void loadItems(Item[] items) {
		addBackBtn();
		_items = items;
		this._itemsBack = _items;
	}
	
	private void addBackBtn() {
		Item[] itemsTemp = new Item[_items.length + 1];
		for(int i = 0; i < _items.length; i++) {
			itemsTemp[i] = _items[i];
		}
		_items = itemsTemp;
		_items[_items.length - 1] = _backItem;
		
	}
	
	public void layoutItems() {
		int spacing = 102;
		if(_items != null) {
			_shiftX = new int[_items.length];
			_shiftY = new int[_items.length];
			
			for(int i = 0; i < _items.length - 1; i++) {
				int newX =((i%7)*(spacing));
				int newY = ((i/7)*(spacing));
				_shiftX[i] = newX - _items[i]._x+50;
				_shiftY[i] = newY - _items[i]._y+50;

				_items[i].shift(_shiftX[i],_shiftY[i]);			
			}
		}
		
		this._itemsBack = _items;
	}
	public void restoreItemLocations(){
		if(_items != null) {
			for(int i = 0; i < _items.length - 1; i++){		
				_items[i].shift(-_shiftX[i],-_shiftY[i]);
			}
			_shiftX = null;
			_shiftY = null;
		}

		this._itemsBack = _items;
	}
	
	public void addItemToInventory(Item addItem){
		Item[] tempItems = new Item[_items.length];
		for(int i = 0; i < tempItems.length; i++)
			tempItems[i] = _items[i];
		
		_items = new Item[tempItems.length+1];
		for(int i = 0; i < tempItems.length; i++)
			 _items[i] = tempItems[i];
		
		_items[_items.length - 1] = addItem;
		addItem._isInInventory = true;
		this._itemsBack = _items;
		
		/*
		for(int i = 0; i < _items.length; i++)
			System.out.println(_items[i]._name);
		 */
	}
}

